<?php

require_once(LIB_PATH.'/libRVT.php');

$rvt = new RVT();

function setInfo($item){
	global $rvt;
	global $smarty;
	
	switch ($rvt->getType($item)){
		case "1":
			$t = "case";
			$i = $rvt->getCase($item);
			$smarty->assign('devices',$rvt->getDevices($item));
			break;
		case "2":
			$t = "device";
			$i = $rvt->getDevice($item);
			$smarty->assign('disks',$rvt->getDisks($item));
			break;
		case "3":
			$t = "disk";
			$i = $rvt->getDisk($item);
			$smarty->assign('partitions',$rvt->getPartitions($item));
			break;
		case "4":
			$t = "partition";
			$i = $rvt->getPartition($item);
			break;
	}
	
	if ($i) $smarty->assign($t,$i);	
	else exit();
}

if ( isset($_POST['action']) ){
	switch ($_POST['action']){
		case "tree":
			$item = (isset($_POST['item']))?$_POST['item']:'';
			switch ($rvt->getType($item)){
				case "0":
					$t = "case";
					$i = $rvt->getCases();
					break;
				case "1":
					$t = "device";
					$i = $rvt->getDevices($item);
					break;
				case "2":
					$t = "disk";
					$i = $rvt->getDisks($item);
					break;
				case "3":
					$t = "partition";
					$i = $rvt->getPartitions($item);
					break;
			}
			$smarty->assign('type',$t);
			$smarty->assign('base',$item);
			$smarty->assign('items',$i);
			$smarty->assign('tree',1);
			break;
		case "info":
			$item = (isset($_POST['item']))?$_POST['item']:'';
			if ($item == "Cases") return '';
			setInfo($item);
			break;
		case "add":
			print $_POST['to'].'-noVaPeroIra';
//			$_POST['to'];
			exit();
			break;
		case "ren":
			print $_POST['name'];
			exit();
//			$_POST['last'];
//			$_POST['name'];
			break;
		case "del":
//			$_POST['name'];
			exit();
			break;	
		case "set":
			$_SESSION['case'] = $_POST['case'];
//			print_r($_SESSION);
			exit();
	}
}
// print_r($rvt->getCases());

$smarty->display($_POST['mod'].'.tpl');

?>
